<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .box1 {
        width: 300px;
        height: 200px;
        border: 1px solid red;
        margin-bottom: 50px;
    }

    .box2 {
        width: 300px;
        height: 50px;
        border: 1px solid red;
    }
</style>

<body>
    <div class="box1"></div>
    <div class="box2"></div>
    <script>
        var areaDiv = document.querySelector(".box1");
        var showMsg = document.querySelector(".box2");

        areaDiv.onmousemove = function () {



            // clientX可以获取鼠标指针的水平坐标
            // clientY可以获取鼠标指针的垂直坐标
            var x = event.clientX;
            var y = event.clientY;

            
            // 在showMsg中显示鼠标的坐标
            showMsg.innerHTML = "X=" + x + ",Y=" + y;
        }
    </script>
</body>

</html>